//
//  YMWelComeViewController.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/22.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit
import SnapKit

class YMWelComeViewController: UIViewController {

    override func loadView() {
        view = bjImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
     
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        
        
       UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
        self.view.layoutIfNeeded()
        
        }) { (_) in
           UIView.animateWithDuration(0.25, animations: { 
            self.messageLabel.alpha = 1
           
            }, completion: { (_) in

                  NSNotificationCenter.defaultCenter().postNotificationName(WBSwiftRootViewControllerNoti, object: "welcome")
           })
        }
    }
    
    //发送通知切换跟控制器
//    NSNotificationCenter.defaultCenter().postNotificationName(WBSwiftRootViewControllerNoti, object: "welcome")
    func setupUI() {
        
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
    headImageView.snp_makeConstraints { (make) in
        make.size.equalTo(CGSize(width: 90, height: 90))
        make.centerX.equalTo(view)
        make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
    }
    
    
    //        MARK: - 懒加载控件
    lazy var bjImageView :UIImageView = UIImageView(imgName: "ad_background")
    
    
    lazy var headImageView:UIImageView = {
        
       let imgv = UIImageView(image: UIImage (named: "avatar_default_big"))
        imgv.sh_setImage(YMUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        imgv.layer.borderColor = ThemeColor.CGColor
        imgv.layer.borderWidth = 2
        imgv.layer.cornerRadius = 45
        imgv.layer.masksToBounds = true
        
        return imgv
    }()
    
    lazy var messageLabel:UILabel = {
       
        let lab = UILabel()
        lab.textColor = UIColor.darkGrayColor()
        lab.font = UIFont.systemFontOfSize(16)
        lab.textAlignment = .Center
        lab.text = "欢迎回来"
        lab.alpha = 0
        return lab
    }()
}
